package cn.sx.service;

/*
 *@program:sx_emall_ssm
 *@author: sx
 *@desc: 商品推荐服务
 *@Time: 2020/9/23  19:34
 */

import cn.sx.dao.TopsDao;
import cn.sx.entity.Tops;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class TopService {

    @Autowired
    private TopsDao topsDao;

    /**
     * 通过商品id和类型获取
     * @param goodId
     * @param type
     * @return
     */
    public Tops getByGoodIdAndType(int goodId,byte type){
        return topsDao.selectByGoodIdAndType(goodId,type);
    }

    /*获取推荐商品列表*/
    public String getGoodIdsByType(byte type) {
        List<String> list = topsDao.selectGoodIdsByType(type);
        return Objects.nonNull(list) ? String.join(",",list) : null;

    }

    /*按商品删除*/
    public boolean deleteByGoodId(int goodId) {
        return topsDao.deleteByGoodId(goodId);
    }

    /*添加商品*/
    public boolean add(int goodId, byte type) {
        Tops tops = new Tops();
        tops.setGoodId(goodId);
        tops.setType(type);
        return topsDao.insert(tops);
    }

    public boolean delete(int goodId, byte type) {
        return  topsDao.deleteByGoodIdAndType(goodId,type);
    }
}
